package domain;

import java.util.ArrayList;
import java.util.List;

public class Copy {

    public enum Condition {
        NEW, GOOD, DAMAGED, WASTE, LOST
    }

    public static long nextInventoryNumber = 1;

    private final long inventoryNumber;
    private final Book book;
    private List<Loan> loans;
    private Condition condition;

    public Copy(Book title) {
        this.book = title;
        loans = new ArrayList<Loan>();
        inventoryNumber = nextInventoryNumber++;
        condition = Condition.NEW;
    }

    public Book getTitle() {
        return book;
    }

    public Condition getCondition() {
        return condition;
    }

    public void setCondition(Condition condition) {
        this.condition = condition;
    }

    public long getInventoryNumber() {
        return inventoryNumber;
    }

    public List<Loan> getLoans() {
        return loans;
    }

    public void addLoan(Loan loan) {
        loans.add(loan);
    }

    public boolean isLent() {
        for (Loan loan : loans) {
            if (loan.isLent()) {
                return true;
            }
        }
        return false;
    }

    @Override
    public int hashCode() {
        return System.identityHashCode(this);
    }

    @Override
    public boolean equals(Object obj) {
        if (this == obj)
            return true;
        return false;
    }
}
